import json,os
from flask import Blueprint,request,redirect,make_response,Response,render_template
from swaager_init import siwa,BaseModel
from application.models.model import *
from tools.data_tools import orm2dict,ret_route,limit_framt
from sqlalchemy import text

index = siwa.blueprint("index", __name__)

@index.route("/index_course",methods=['get'])
def index_course():
    serach = request.args.get('serach')
    course_sql1 = Course.query.filter(Course.name.like(f"%{serach}%")).all()
    news_sql2 = News.query.filter(News.title.like(f"%{serach}%")).all()
    ret_data = {
        'course':orm2dict(course_sql1),
        'news':orm2dict(news_sql2),
    }
    return ret_route(data=ret_data)
